<template>
	<view>
		<form @submit="submitSub" :style="colorStyle">
			<view class="payment-top flex-row row-column row-center-wrapper">
				<span class="name">可提现金额</span>
				<view class="pic">
					￥<span class="pic-font">{{ userAmount.realPrice || 0 }}</span>
				</view>
			</view>
			<view class="payment">
				<view class="nav flex-row row-around row-middle">
					<view class="item" :class="active==index?'on':''" v-for="(item,index) in navRecharge" :key="index"
						@click="navRecharges(index)">{{item}}</view>
				</view>
				<view class="tip">
					<view class='input'><text>￥</text><input placeholder="0.00" type='number'
							placeholder-class='placeholder' :value="number" name="number"></input></view>
					<view class="tips-title">
						<view style="font-weight: bold; font-size: 26rpx;">提示：</view>
						<view style="margin-top: 10rpx;">当前可提现金额为 <text
								class='font-color'>￥{{userAmount.realPrice || 0}}</text>，赠送金额为<text
								class='font-color'>￥{{userAmount.lockPrice}}</text></view>
					</view>
					<view class="tips-box">
						<view class="tips mt-30">注意事项：</view>
						<view class="tips-samll">
							提现后，金额会在一天到账
						</view>
						<view class="tips-samll">
							账户提现出现问题可联系商城客服，也可拨打商城客服热线：1380013800
						</view>
					</view>
				</view>
				<button class='but bg-color' formType="submit">立即提现</button>
			</view>
		</form>
	</view>
</template>

<script>
	import {
		getUserAmount,
		applyOut
	} from '@/api/user.js';
	import {
		toLogin
	} from '@/libs/login.js';
	import {
		mapGetters
	} from "vuex";
	export default {
		components: {},
		data() {
			let that = this;
			return {
				navRecharge: ['账户提现'],
				active: 0,
				number: '',
				userAmount: {},
				placeholder: "0.00",
			};
		},
		computed: mapGetters(['isLogin', 'uid']),
		watch: {
			isLogin: {
				handler: function(newV, oldV) {
					if (newV) {
						this.getUserAmount();
					}
				},
				deep: true
			}
		},
		onLoad(options) {
			if (this.isLogin) {
				this.getUserAmount();
			} else {
				toLogin();
			}
		},
		methods: {

			navRecharges: function(index) {
				this.active = index;
			},
			/**
			 * 获取用户信息
			 */
			getUserAmount: function() {
				let that = this;
				getUserAmount({
					userInfoId: this.uid
				}).then(res => {
					that.$set(that, 'userAmount', res.value);
				})
			},
			/*
			 * 用户提现
			 */
			submitSub: function(e) {
				let that = this
				let value = e.detail.value.number;
				// 提现
				if (!that.active) {
					if (parseFloat(value) < 0 || parseFloat(value) == NaN || value == undefined || value == "") {
						return that.$util.Tips({
							title: '请输入金额'
						});
					}
					uni.showModal({
						title: '提现余额',
						content: '确认是否提现余额到微信',
						success(res) {
							if (res.confirm) {
								if (parseFloat(that.userAmount.realPrice) < parseFloat(value)) {
									return that.$util.Tips({
										title: '提现失败，余额不足',
									});
								}
								applyOut({
									outPrice: parseFloat(value),
									userInfoId: that.uid,
								}).then(res => {
									return that.$util.Tips({
										title: '提现成功',
										icon: 'success'
									}, {
										tab: 5,
										url: '/pages/users/user_money/index'
									});
								}).catch(err => {
									return that.$util.Tips({
										title: err
									})
								});
							} else if (res.cancel) {
								return that.$util.Tips({
									title: '已取消'
								});
							}
						},
					})
				}
			}
		}
	}
</script>

<style lang="scss">
	page {
		width: 100%;
		height: 100%;
		background-color: #fff;
	}

	.bgcolor {
		background-color: #3CBB45
	}

	.payment {
		position: relative;
		top: -60rpx;
		width: 100%;
		background-color: #fff;
		border-radius: 10rpx;
		padding-top: 25rpx;
		border-top-right-radius: 39rpx;
		border-top-left-radius: 39rpx;
	}

	.payment .nav {
		height: 75rpx;
		line-height: 75rpx;
		padding: 0 100rpx;
	}

	.payment .nav .item {
		font-size: 30rpx;
		color: #333;
	}

	.payment .nav .item.on {
		font-weight: bold;
		border-bottom: 4rpx solid #3CBB45;
	}

	.payment .input {
		display: flex;
		align-items: center;
		justify-content: center;
		border-bottom: 1px dashed #dddddd;
		margin: 60rpx auto 0 auto;
		padding-bottom: 20rpx;
		font-size: 56rpx;
		color: #333333;
		flex-wrap: nowrap;

	}

	.payment .input text {
		padding-left: 106rpx;
	}

	.payment .input input {
		padding-right: 106rpx;
		width: 300rpx;
		height: 94rpx;
		text-align: center;
		font-size: 70rpx;
	}

	.payment .placeholder {
		color: #d0d0d0;
		height: 100%;
		line-height: 94rpx;
	}

	.payment .tip {
		font-size: 26rpx;
		color: #888888;
		padding: 0 30rpx;
		margin-top: 25rpx;
	}

	.payment .but {
		color: #fff;
		font-size: 30rpx;
		width: 700rpx;
		height: 86rpx;
		border-radius: 50rpx;
		margin: 46rpx auto 0 auto;
		line-height: 86rpx;
	}

	.payment-top {
		width: 100%;
		height: 350rpx;
		background-color: #3CBB45;

		.name {
			font-size: 26rpx;
			color: rgba(255, 255, 255, 0.8);
			margin-top: -38rpx;
			margin-bottom: 30rpx;
		}

		.pic {
			font-size: 32rpx;
			color: #fff;
		}

		.pic-font {
			font-size: 78rpx;
			color: #fff;
		}
	}

	.tips-box {
		.tips {
			font-size: 28rpx;
			color: #333333;
			font-weight: 800;
			margin-bottom: 14rpx;
			margin-top: 20rpx;
		}

		.tips-samll {
			font-size: 24rpx;
			color: #333333;
			margin-bottom: 14rpx;
		}

		.tip-box {
			margin-top: 30rpx;
		}
	}

	.tips-title {
		margin-top: 20rpx;
		font-size: 24rpx;
		color: #333;
	}
</style>